﻿using MediatR;
using S.Produce.Domains;
using S.Produce.Infrastructure;
using S.Produce.Read.Api.Application.Commands.BreedingCommands;

namespace S.Produce.Read.Api.Application.CommandHandlers.BreedingCommandHandlers
{    
    public class BreedingEarCommandHandler : IRequestHandler<BreedingEarCommand, List<Breeding>>
    {
        private readonly IRepository<Breeding> _repository;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="repository"></param>
        public BreedingEarCommandHandler(IRepository<Breeding> repository)
        {
            _repository = repository;
        }

        public async Task<List<Breeding>> Handle(BreedingEarCommand request, CancellationToken cancellationToken)
        {
            var info = await _repository.SelAllAsync(x => x.Earbugles == request.EarNumber);
            return info.Where(x => !x.IsDel).ToList();
        }
    }
}
